<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .search {
        position: relative;
        height: 246px;
        width: 100%;
        min-width: 1000px;
        background-size: cover;
        background-position: center center;
        background-image: url(https://h5static.kuwo.cn/www/kw-www/img/searchBg.07b12b9.png);
      }
      .search input {
        width: 720px;
        height: 55px;
        background: white;
        position: relative;
        top: 90px;
        line-height: 54px;
        left: 390px;
        text-indent: 20px;
        font-size: 20px;
      }
      .search ul {
        border-radius: 10px;
        list-style: none;
        background: white;
        position: absolute;
        width: 730px;
        top: 160px;
        left: 390px;
        font-size: 18px;
        overflow: hidden;
      }
      .search ul li {
        line-height: 40px;
        text-indent: 30px;
      }
      .search ul li:hover {
        background: #ccc;
      }
      .search ul li span {
        margin: auto;
        text-align: center;
        text-indent: 0;
        display: inline-block;
        width: 20px;
        height: 20px;
        line-height: 20px;
        font-size: 13px;
        background-color: red;
        color: #fff;
      }
      .list {
        width: 1120px;
        margin: 0 auto;
        list-style: none;
        display: flex;
        justify-content: space-around;
        flex-wrap: wrap;
      }
      .list li {
        width: 200px;
        margin-top: 20px;
      }
      .list li div {
        width: 200px;
        height: 112px;
        overflow: hidden;
      }
      .list li img {
        width: 100%;
        transition: 1s;
      }
      .list li img:hover {
        transform: scale(1.2);
      }
      .vio {
        width: 800px;
        position: fixed;
        margin: 0 auto;
        left: 0;
        top: 100px;
        bottom: 0;
        right: 0;
      }
      video {
        width: 800px;
      }
      .vio span {
        display: block;
        width: 20px;
        height: 20px;
        position: absolute;
        top: 0;
        right: 0;
        background-color: #fff;
        padding: 5px;
        font-size: 20px;
        text-align: center;
        line-height: 20px;
      }
      .vio span:hover{
        background-color: red;
        color: #fff;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div class="search">
        <input
          type="text"
          v-model="search"
          placeholder="请输入关键词，按回车搜索"
          @input="searchList(); mvLists()"
          @focus="isSearch=true"
          @blur="isSearch=false;"
        />
        <ul v-show="isSearch">
          <li
            v-for="(item,index) in searchData"
            @mousedown="search = item;mvLists()"
          >
            <span>{{index+1}}</span>{{item}}
          </li>
        </ul>
      </div>
      <ul class="list">
        <li v-for="item in mvData" :key="item.id">
          <div>
            <img :src="item.pic" alt="" @click="id=item.id;isMv=true;mvBo()" />
          </div>
          <h3>{{item.name.substr(0,9)+'...'}}</h3>
          <p>{{item.artist}}</p>
        </li>
      </ul>
      <div class="vio" v-show="isMv">
        <video controls autoplay :src="mvUrl"></video>
        <span @click="isMv=false">×</span>
      </div>
    </div>
    <script src="./axios.min.js"></script>
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          search: "",
          searchData: [],
          isSearch: false,
          mvData: [],
          id: "",
          mvUrl: "",
          isMv: false,
        },
        created() {
          this.searchList();
          this.mvLists();
        },
        methods: {
          // 搜索列表
          async searchList() {
            let res = await axios.get(
              "http://101.43.173.17:9090/api/www/search/searchKey?key=" +
                this.search
            );
            let data = res.data.data.map((item) => {
              return item.indexOf("\r\n") > -1
                ? item.split("\r\n")[0].split("=")[1]
                : item;
            });
            this.searchData = data;
          },
          // 歌曲列表
          async mvLists() {
            let res = await axios.get(
              "http://101.43.173.17:9090/api/www/search/searchMvBykeyWord?key=" +
                (this.search == "" ? "周杰伦" : this.search)
            );
            this.mvData = res.data.data.mvlist;
          },
          // 播放mv
          async mvBo() {
            let res = await axios.get(
              `http://101.43.173.17:9090/api/v1/www/music/playUrl?mid=${this.id}&type=mv`
            );
            this.mvUrl = res.data.data.url;
          },
        },
      });
    </script>
  </body>
</html>
